package aidansmeaton.airport;

import java.util.List;

import aidansmeaton.airport.database.DatabaseHelper;
import aidansmeaton.airport.overlays.AirportItemizedOverlay;
import aidansmeaton.airport.overlays.DirectionPathOverlay;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class AirportMapActivity extends MapActivity {
	
	public int DEFAULT_ZOOM_LEVEL = 7;
	
	private MapView mapView;
	private MapController mapController;
	private List<Overlay> mapOverlays;
	private AirportItemizedOverlay[] airportOverlays;
	private DirectionPathOverlay routeOverlay;
	private Drawable[] airportDrawables;
	
	private DatabaseHelper db;
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_main);
        
        mapView = (MapView) findViewById(R.id.mapview);
        mapOverlays = mapView.getOverlays();
        
        /* Enable zoom controls. */
        mapView.setBuiltInZoomControls(true);
        mapView.displayZoomControls(true);
		mapController = mapView.getController();
		mapController.setZoom(DEFAULT_ZOOM_LEVEL);
		
		db = DatabaseHelper.getInstance(this);
		
		
		createAndAddAirportsOverlay();
        
    }
    
    private void createAndAddAirportsOverlay() {
				
    	airportDrawables = new Drawable[6];
		airportDrawables[0] = getResources().getDrawable(R.drawable.map_airport_size0);
		airportDrawables[1] = getResources().getDrawable(R.drawable.map_airport_size1);
		airportDrawables[2] = getResources().getDrawable(R.drawable.map_airport_size2);
		airportDrawables[3] = getResources().getDrawable(R.drawable.map_airport_size3);
		airportDrawables[4] = getResources().getDrawable(R.drawable.map_airport_size4);
		airportDrawables[5] = getResources().getDrawable(R.drawable.map_airport_size5);
		
		airportOverlays = new AirportItemizedOverlay[airportDrawables.length];
				
		for (int i = 0; i < airportDrawables.length; i++){
			airportOverlays[i] = new AirportItemizedOverlay(airportDrawables[i],getBaseContext(),mapView,i);
			airportOverlays[i].refresh();
			mapOverlays.add(airportOverlays[i]);			
		}
		
		routeOverlay = new DirectionPathOverlay(new GeoPoint(55871940,-4433050),new GeoPoint(41297070,2078460));
		mapOverlays.add(routeOverlay);
		
    }
		
	

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	
	
}